package cn.pid21.client.request;

import cn.pid21.client.model.PidService;
import cn.pid21.client.util.RequestBodyUtil;
import cn.pid21.client.util.RequestUtil;
import lombok.Getter;
import okhttp3.Headers;
import okhttp3.Request;

/**
 * PidUpdateRequest
 *
 * @author 郭志斌
 * @version 1.0.0
 * @date 2019/8/16 16:00
 */
@Getter
public class PidUpdateRequest implements PidRequest {

    /**
     * PID update json 格式数据
     */
    private String json;

    private PidUpdateRequest(){}

    /**
     * Builder 方法
     *
     * @return PidUpdateRequest
     */
    public static PidUpdateRequest builder(){
        return new PidUpdateRequest();
    }

    /**
     * 设置 json 属性
     *
     * @param json
     * @return PidUpdateRequest
     */
    public PidUpdateRequest json(String json){
        this.json = json;
        return this;
    }

    @Override
    public Request build(String clientId,String secret) {
        Headers headers = RequestUtil.headers(PidRequestHeader.builder().clientId(clientId).secret(secret));
        return RequestUtil.put(headers, RequestBodyUtil.json(json),service().getName());
    }

    @Override
    public PidService service() {
        return PidService.UPDATE_SERVICE;
    }
}
